package com.ibiz.znjd.znjd;

import com.ibiz.znjd.MainApplication;


import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * 预警相关工具类(弃用)
 */
@Deprecated
public class PersonUtil {

    /**
     * 发送越界预警信息
     * @param app
     */
    public static void updatePerson(MainApplication app){
        String personUrl = app.envMap.get("personUrl");
        String token = app.envMap.get("token");
        String personid = app.envMap.get("personid");
        if( personUrl == null || token == null || personid == null){
            return;
        }

        // 发起请求
        OkHttpClient client = new OkHttpClient();
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        String jsonStr = "{\"yjlx\": null}";
        RequestBody body = RequestBody.create(JSON,jsonStr);
        Request request = new Request.Builder()
                .header("Authorization", "Bearer " + token)
                .header("deviceType", "app")
                .url(personUrl+personid)
                .post(body)
                .build();
        Call call = client.newCall(request);

        // 请求回调
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                System.out.println("更新人员信息失败！");
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String result = response.body().string();
                if(response.isSuccessful()){
                    //处理UI需要切换到UI线程处理
                    System.out.println("更新人员信息成功：");
                }else{
                    System.out.println("更新人员信息失败：");
                }
                System.out.println(result);
            }
        });
    }
}
